// xc_lshop/shop/gift/mycard/list.js
var actbill = require('../../model/pack_list')
// import drawQrcode from '../../../../utils/weapp-qrcode.js';

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],
  
  /**
   * 页面的初始数据
   */
  data: {
    navstatus:"0",
    nav:[
      {status:"0",name:"全部"},{status:"1",name:"未使用"},{status:"2",name:"使用中"},{status:"3",name:"已使用"},{status:"-1",name:"已失效"},
    ],
    statuscolor:{
      1:{
        name:'未使用',background:"#FCAB20"
      },
      2:{
        name:'使用中',background:"#30A75D"
      },
      3:{
        name:'已使用',background:"#848484"
      },
      '-1':{
        name:'已失效',background:"#CBCBCB"
      },  
    },
    sourceway:{
        'buy':'自行购买',
        'sys':'系统赠送',
        'user':'用户赠送',
    },
    modellist:[ //删
      {
        id:1,
        status:1,
        simg:"https://img.yzcdn.cn/vant/cat.jpeg",
        name:"【新畅】端午主题卡",
        source:'sys',
        effectiveend:"2020-05-07 10:10:10",
      }
    ]
  },
  blank(){

  },
  showqrcode(e){
    var item=e.currentTarget.dataset.item;
    if(item.status==1 || item.status==2){
      this.selectComponent('#qrcode').init(item.id)

    }

  },
 
  exchange(e){
    var item=e.currentTarget.dataset.item;
    // console.log("item")
    // console.log(item)
    this.selectComponent('#exchange').init(item)
  },
  onClickNav(e){
    console.log("e")
    console.log(e)
    this.setData({
      navstatus:e.detail.name
    })
    this.getpagelist(this,1)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  xcloaddata: function (options, config) {
    // var that=this;
    // this.getclass()
   
  },
  getpagelist(that, rest, strwhere) {
    if (!strwhere) {
      strwhere = {};
    }
    // strwhere["status"] = 1;
    strwhere["status"] = this.data.navstatus;
    if (rest == 1) {
      
      that.setData({ modellist: [] });
    }
    actbill.offset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};

      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {

           
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        }
        else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      wx.stopPullDownRefresh();
      console.log(updatemdoel)
      that.setData(updatemdoel);
    });
  },
  showmore(e){
     var index=e.currentTarget.dataset.index;
     var name='modellist['+index+'].showmore'
     this.setData({
       [name]:!this.data.modellist[index].showmore
     })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getpagelist(this,1)
    this.selectComponent('#exchange').rechoose()

    // this.selectComponent('#exchange').onChangeAll(-1)
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    this.getpagelist(that, -1)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    
    var index=e.target.dataset.detail;
    var item=this.data.modellist[index]
    console.log("onShareAppMessage")

    console.log(item)
    var app = getApp()
    var sharetitle = item.name

    var shareimg = item.simg


    // var sharepath =""
    
    var sharepath ="/xc_lshop/shop/pack/mycard/infor?id="+item.id+"&shareid="+app.globalData.member.member_id

  // console.log(sharetitle)
  // console.log(sharepath)
  // console.log(shareimg)

    return {
      title: sharetitle,
      path: sharepath,
      imageUrl: shareimg
    }
  }
})